
import {get,post} from '../../http'
const PLACE = 'PLACE';
const BOAT= 'BOAT';
const BOAT1 = 'BOAT1'
const ADDBOAT = 'ADDBOAT'

const initState={
	res:false,
	areaList:[
        {regionName:''}
    ],
    shipList:[
       
	],
	shipList1:{},
	addstate:false
}
// reducer1
export function findLists(state=initState, action){
	switch(action.type){
		case PLACE:
            return Object.assign({},state,{areaList:action.res})
        case BOAT:
			return Object.asssign({},state,{shipList:action.res})
		case BOAT1:
			return Object.assign({},state,{shipList1:action.res})
		case ADDBOAT:
            return Object.assign({},state,{addstate:action.res})
		default:
			return state
	}
} 


function placeOfSuccess(res){
	return {type:PLACE,res:res}
}

function boatSuccess(res){
	return {type:BOAT,res:res}
}
function addboatSuccess(res){
	return {type:ADDBOAT,res:res}
}
function boat1Success(res){
	return {type:BOAT1,res:res}
}


export function placeOf (){
	return dispatch=>{
		post('/ship/queryRegion.do',{})
			.then(res=>{
				console.log(res)
				dispatch(placeOfSuccess(res.areaList));
			})		
	}
	
}

export function boatSeach ({shipName,dunWei,huoZhong,chuFaDi}){
    let data = {
        shipName,
        dunWei,
        huoZhong,
        chuFaDi
    }
	return dispatch=>{
		post('/ship/queryShip.do',data)
			.then(res=>{
				console.log(res)
				dispatch(boatSuccess(res.shipList));
			})		
	}
	
}

export function addBoatSeach (shipId){
    let data = {
        shipId,
      
    }
	return dispatch=>{
		post('/ship/insertShipAndByShipId.do',data)
			.then(res=>{
				console.log(res)
				dispatch(addboatSuccess(res.SUCCESS));
			})		
	}
	
}

export function boatSeach1 ({shipName,page,limit}){
    let data = {
        shipName,
        page,
        limit,
    }
	return dispatch=>{
		post('/ship//selectAllShipsByShipName.do',data)
			.then(res=>{
				console.log(res)
				dispatch(boat1Success(res.shipsList));
			})		
	}
	
}


